# -*- coding: utf-8 -*-
# author yzs
# date 2019-02-23
#
# 分治法解最近对问题
# Description
# 最近对问题：使用分治算法解决最近对问题
# Input
# 第一行为测试用例个数。后面第一行表示一个用例，一个用例为一些平面上点的集合，点与点之间用逗号隔开，
# 一个点的两个坐标用空格隔开。坐标值都是正数。
# Output
# 对每一个用例输出两个距离最近的点（坐标使用空格隔开），用逗号隔开，先按照第一个坐标大小排列，再按照第二个坐标大小排列。
# 如果有多个解，则按照每个解的第一个点的坐标排序，连续输出多个解，用逗号隔开
# Sample Input 1
# 1
# 1 1,2 2,3 3,4 4,5 5,1.5 1.5
# Sample Output 1
# 1 1,1.5 1.5,1.5 1.5,2 2
import math


def nearest_dot(s):
    s_len = len(s)
    left = s[0: s_len // 2]
    right = s[s_len // 2:]
    mid_x = (left[-1][0] + right[0][0]) / 2.0
    global min_d
    global nearest_dots

    if len(left) > 2:
        l_min = nearest_dot(left)  # 左侧部分最近点对
    else:
        l_min = left
    if len(right) > 2:
        r_min = nearest_dot(right)  # 右侧部分最近点对
    else:
        r_min = right
    if len(l_min) > 1:
        dis_l = get_distance(l_min)
    else:
        dis_l = float("inf")
    if len(r_min) > 1:
        dis_r = get_distance(r_min)
    else:
        dis_r = float("inf")
    # 最近点对距离
    d = min(dis_l, dis_r)
    if d <= min_d:
        min_d = d
        if d < min_d:
            nearest_dots = []
        if dis_l == d and l_min not in nearest_dots:
            nearest_dots.append(l_min)
        if dis_r == d and r_min not in nearest_dots:
            nearest_dots.append(r_min)

    mid_min = []
    for i in left:
        # 如果左侧部分与中间线的距离<=d
        if mid_x - i[0] <= d:
            for j in right:
                # 如果右侧部分点在i点的(d,2d)之间
                if abs(i[0] - j[0]) <= d and abs(i[1] - j[1]) <= d:
                    # ij两点的间距若小于d则加入队列
                    if get_distance((i, j)) <= d:
                        mid_min.append([i, j])
    if mid_min:
        dic = {}
        for i in mid_min:
            dic[get_distance(i)] = i
        dist = sorted(dic)
        for i in range(len(dist)):
            if dist[i] <= min_d:
                if dist[i] < min_d:
                    nearest_dots = []
                if dic[dist[i]] not in nearest_dots:
                    nearest_dots.append(dic[dist[i]])
            else:
                break
        return dic[dist[0]]
    elif dis_l > dis_r:
        return r_min
    elif dis_l <= dis_r:
        return l_min


# 求点对的距离
def get_distance(p):
    return math.sqrt((p[0][0] - p[1][0]) ** 2 + (p[0][1] - p[1][1]) ** 2)


def to_int(x):
    x = int(x) if x == int(x) else x
    return x


def divide_conquer(s):
    s.sort(key=lambda elem: elem[0])
    nearest_dot(s)
    res = sorted(nearest_dots, key=lambda p: (p[0][0], p[0][1]))
    res_s = []
    for dots in res:
        for dot in dots:
            res_s.append(str(to_int(dot[0]))+' '+str(to_int(dot[1])))
    print(','.join(res_s))


min_d = float("inf")
nearest_dots = []
t = int(input().strip())
for i in range(t):
    data = list(map(str, input().strip().split(',')))
    points = []
    for i in data:
        points.append((float(i.split()[0]), float(i.split()[1])))
    divide_conquer(points)


